<%request.setAttribute("pageName",new String("gadgets"));%><%@include file="/include/header.jsp" %>

<%

   	PersistenceManager pm = PMF.get().getPersistenceManager();
    Query query = pm.newQuery(Gadget.class);
    query.setOrdering("creation desc");
    //query.setResult("name,status,type,help_url,creation");
    String title ="";
    String description ="";
    int gadgetsOnRow = 2;
    int count = 0;
    try 
    {
   	 List <Gadget> gadgets  = (List <Gadget>) query.execute();
   	 if (gadgets.iterator().hasNext()) {
   		out.print("<table  width='100%'>");
         for (Gadget g : gadgets) 
         {
        	 
        	// check for gadget ststus is onlione or 
        	if(!g.isVisible())
       			continue;
        	if(count%gadgetsOnRow == 0)
           	 out.print("<tr valign=\"top\">");
        	
        	if(g.getTitle()!=null && !g.getTitle().isEmpty())
        		title = g.getTitle();
        	else
        		title = g.getName();
       		out.print("<td  align='center'> <h3><a href='gadget.jsp?gname="+g.getName()+"'>"+title+"</a></h3><br>");
       		       	
       		out.print("<a href='gadget.jsp?gname="+g.getName()+"'><img src='"+UrlUtils.getGadgetHome(g.getName())+"thumbnail.png'></a></td>");
       		
       		if(count%gadgetsOnRow == (gadgetsOnRow-1))
              	 out.print("</tr>");
     
        	 count++;
         }
         out.println("</table>");
     } 
   	 

    }
    finally 
    {
        query.closeAll();
        pm.close();
    }
   %><%@include file="/include/footer.jsp" %>